package com.share.thread;

/**
 * @desc:
 * @author:caifan
 * @date:2022/1/29
 */
public class TicketThread {

    public static void main(String[] args) {
        int i = 1;
        while (i < 100) {
            new Thread(new Ticket("窗口1", i++)).start();
            new Thread(new Ticket("窗口2", i++)).start();
            new Thread(new Ticket("窗口3", i++)).start();
        }
    }
}

class Ticket implements Runnable {

    private String window;
    private int ticketNo;


    public Ticket(String window, int ticketNo) {
        this.window = window;
        this.ticketNo = ticketNo;
    }

    @Override
    public void run() {
        synchronized (this) {
            try {
                System.out.println(Thread.currentThread().getName() + ":" + window + "*票号&&" + ticketNo);
                Thread.sleep(100);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
